#include "timer.h"

timer::timer() {
    startTicks = 0;
    pauseTicks = 0;
    started = false;
    paused = false;
}

void timer::start() {
    if(!paused) {
        started = true;
        paused = false;
        startTicks = SDL_GetTicks();
    } else {
        paused = false;
        startTicks = SDL_GetTicks() - pauseTicks;
        pauseTicks = 0;
    }
}

void timer::pause() {
    paused = true;
    pauseTicks = SDL_GetTicks() - startTicks;
}

void timer::stop() {
    started = false;
    paused = false;
}

int timer::getTicks() {
    if(started) {
        if(paused) {
            return pauseTicks;
        } else {
            return SDL_GetTicks() - startTicks;
        }
    }
    return 0;
}

bool timer::isStarted() {
    return started;
}

bool timer::isPaused() {
    return paused;
}
